n = int(input())


def isValid(num):
    stack = []
    while num:
        t = num % 10
        num //= 10
        if stack and t > stack[-1]:
            return False
        stack.append(t)
    return True


result = 0
for i in range(1, n + 1):
    if isValid(i):
        result += 1
print(result)
